package edu.gatech.oad.OTConfig;
import java.awt.event.*;
import javax.swing.*;
import net.miginfocom.swing.MigLayout;


public class TrailPanelSolo extends JPanel {
	
	private ButtonGroup rationGroup, paceGroup;
	private ButtonListener listener;
	private JButton btnRest, btnKeepGoing;
	private JourneyController journeyCtrl;
	private JRadioButton rdbtnFilling, rdbtnMeager, rdbtnBareBones, rdbtnSteady, rdbtnStrenuous, rdbtnGrueling;
	private JLabel curMoneyLabel, curRationsLabel, curMilesTraveledLabel, curMilesToNextLabel,
	playerHealthLabel, settlerOneHealthLabel, settlerTwoHealthLabel, settlerThreeHealthLabel, settlerFourHealthLabel;
	
	/**This is the main panel for the Trail Frame.
	 * 
	 * @author Amy Lambeth
	 * @version 1.0 10/24/2011
	 * 
	 */
	private static final long serialVersionUID = 5316492254188346160L;

	/**
	 * Create the panel.
	 */
	public TrailPanelSolo() {
		setLayout(new MigLayout("", "[70.00][49.00][72.00][][85.00][98.00]", "[][][][][][][][20.00][20.00][20.00][][20.00]"));
		listener = new ButtonListener();
		journeyCtrl = new JourneyController();
		
		rdbtnFilling = new JRadioButton("Filling");
		rdbtnFilling.setSelected(true);
		add(rdbtnFilling, "cell 0 6");
		
		rdbtnMeager = new JRadioButton("Meager");
		add(rdbtnMeager, "cell 1 6");
		
		rdbtnBareBones = new JRadioButton("Bare Bones");
		add(rdbtnBareBones, "cell 2 6");
		
		rdbtnSteady = new JRadioButton("Steady");
		rdbtnSteady.setSelected(true);
		add(rdbtnSteady, "cell 3 6");
		
		rdbtnStrenuous = new JRadioButton("Strenuous");
		add(rdbtnStrenuous, "cell 4 6");
		
		rdbtnGrueling = new JRadioButton("Grueling");
		add(rdbtnGrueling, "cell 5 6");
		
		rationGroup.add(rdbtnFilling);
		rationGroup.add(rdbtnMeager);
		rationGroup.add(rdbtnBareBones);
		
		paceGroup.add(rdbtnSteady);
		paceGroup.add(rdbtnStrenuous);
		paceGroup.add(rdbtnGrueling);
		
		JLabel dateLabel = new JLabel("Start Date:");
		add(dateLabel, "cell 0 7");
		
		JLabel startDateLabel = new JLabel("5/1/1848");
		add(startDateLabel, "cell 1 7");
		
		JLabel locationLabel = new JLabel("Location:");
		add(locationLabel, "cell 2 7");
		
		JLabel curLocationLabel = new JLabel("On The Trail");
		add(curLocationLabel, "cell 3 7");
		
		btnKeepGoing = new JButton("Keep Going");
		add(btnKeepGoing, "cell 4 7");
		btnKeepGoing.addActionListener(listener);
		
		btnRest = new JButton("Rest");
		add(btnRest, "cell 5 7");
		btnRest.addActionListener(listener);
		
		JLabel moneyLabel = new JLabel("Money:");
		moneyLabel.setHorizontalAlignment(SwingConstants.LEFT);
		add(moneyLabel, "cell 0 8");
		
		curMoneyLabel = new JLabel("0");
		add(curMoneyLabel, "cell 1 8");
		
		JLabel milesTraveledLabel = new JLabel("Miles Traveled:");
		add(milesTraveledLabel, "cell 2 8");
		
		curMilesTraveledLabel = new JLabel("0");
		add(curMilesTraveledLabel, "cell 3 8");
		
		JButton btnParty = new JButton("Party");
		btnParty.setEnabled(false);
		add(btnParty, "cell 4 8");
		
		JButton btnInventory = new JButton("Inventory");
		btnInventory.setEnabled(false);
		add(btnInventory, "cell 5 8");
		
		JLabel rationsLabel = new JLabel("Rations:");
		add(rationsLabel, "cell 0 9");
		
		curRationsLabel = new JLabel("0");
		add(curRationsLabel, "cell 1 9");
		
		JLabel milesToNextLabel = new JLabel("Miles to Next:");
		add(milesToNextLabel, "cell 2 9");
		
		curMilesToNextLabel = new JLabel("100");
		add(curMilesToNextLabel, "cell 3 9");
		
		JButton btnMenu = new JButton("Menu");
		btnMenu.setEnabled(false);
		add(btnMenu, "cell 4 9");
		
		JButton btnNewButton = new JButton("Map");
		btnNewButton.setEnabled(false);
		add(btnNewButton, "cell 5 9");
		
		JLabel playerLabel = new JLabel("Player");
		add(playerLabel, "cell 1 10");
		
		JLabel settlerOneLabel = new JLabel("Settler One");
		add(settlerOneLabel, "cell 2 10");
		
		JLabel settlerTwoLabel = new JLabel("Settler Two");
		add(settlerTwoLabel, "cell 3 10");
		
		JLabel settlerThreeLabel = new JLabel("Settler Three");
		add(settlerThreeLabel, "cell 4 10");
		
		JLabel settlerFourLabel = new JLabel("Settler Four");
		add(settlerFourLabel, "cell 5 10");
		
		JLabel healthLabel = new JLabel("Health:");
		add(healthLabel, "cell 0 11");
		
		playerHealthLabel = new JLabel("Healthy");
		add(playerHealthLabel, "cell 1 11");
		
		settlerOneHealthLabel = new JLabel("Healthy");
		add(settlerOneHealthLabel, "cell 2 11");
		
		settlerTwoHealthLabel = new JLabel("Healthy");
		add(settlerTwoHealthLabel, "cell 3 11");
		
		settlerThreeHealthLabel = new JLabel("Healthy");
		add(settlerThreeHealthLabel, "cell 4 11");
		
		settlerFourHealthLabel = new JLabel("Healthy");
		add(settlerFourHealthLabel, "cell 5 11");

	}
	
	public void updateLabels(){
		curMoneyLabel.setText(""+Wagon.getInventoryController().getWagonInventory().getMoney());
		curRationsLabel.setText(""+Wagon.getInventoryController().getWagonInventory().get(1).getQuantity());
		curMilesTraveledLabel.setText(""+journeyCtrl.getJourney().getMilesTraveled());
		curMilesToNextLabel.setText(""+(100 - ((journeyCtrl.getJourney().getMilesTraveled()) % 100)));
		if(Wagon.getPlayer().getHealth().equals(HealthEnum.HEALTHY)){
			playerHealthLabel.setText("Healthy");
		}
		else if(Wagon.getPlayer().getHealth().equals(HealthEnum.ILL)){
			playerHealthLabel.setText("Ill");
		}
		else if(Wagon.getPlayer().getHealth().equals(HealthEnum.DEAD)){
			playerHealthLabel.setText("Dead");
		}
		
		
		if(Wagon.getSettlerOne().getHealth().equals(HealthEnum.HEALTHY)){
			settlerOneHealthLabel.setText("Healthy");
		}
		else if(Wagon.getSettlerOne().getHealth().equals(HealthEnum.ILL)){
			settlerOneHealthLabel.setText("Ill");
		}
		else if(Wagon.getSettlerOne().getHealth().equals(HealthEnum.DEAD)){
			settlerOneHealthLabel.setText("Dead");
		}
		
		
		if(Wagon.getSettlerTwo().getHealth().equals(HealthEnum.HEALTHY)){
			settlerTwoHealthLabel.setText("Healthy");
		}
		else if(Wagon.getSettlerTwo().getHealth().equals(HealthEnum.ILL)){
			settlerTwoHealthLabel.setText("Ill");
		}
		else if(Wagon.getSettlerTwo().getHealth().equals(HealthEnum.DEAD)){
			settlerTwoHealthLabel.setText("Dead");
		}
		
		if(Wagon.getSettlerThree().getHealth().equals(HealthEnum.HEALTHY)){
			settlerThreeHealthLabel.setText("Healthy");
		}
		else if(Wagon.getSettlerThree().getHealth().equals(HealthEnum.ILL)){
			settlerThreeHealthLabel.setText("Ill");
		}
		else if(Wagon.getSettlerThree().getHealth().equals(HealthEnum.DEAD)){
			settlerThreeHealthLabel.setText("Dead");
		}
		
		if(Wagon.getSettlerFour().getHealth().equals(HealthEnum.HEALTHY)){
			settlerFourHealthLabel.setText("Healthy");
		}
		else if(Wagon.getSettlerFour().getHealth().equals(HealthEnum.ILL)){
			settlerFourHealthLabel.setText("Ill");
		}
		else if(Wagon.getSettlerFour().getHealth().equals(HealthEnum.DEAD)){
			settlerFourHealthLabel.setText("Dead");
		}
	}
	
	private class ButtonListener implements ActionListener{
		
		public void actionPerformed(ActionEvent event){
			if(event.getSource().equals(btnRest)){
				journeyCtrl.rest();
				if(Wagon.getInventoryController().getWagonInventory().get(1).getQuantity() < 0){
					Game.endGame();
				}
				updateLabels();
			}
			else if(event.getSource().equals(btnKeepGoing)){
				journeyCtrl.proceed();
				if(Wagon.getInventoryController().getWagonInventory().get(1).getQuantity() < 0){
					Game.endGame();
				}
				updateLabels();
			}
			else if(event.getSource().equals(rdbtnFilling)){
				Wagon.setRation("Filling");
			}
			else if(event.getSource().equals(rdbtnMeager)){
				Wagon.setRation("Meager");
			}
			else if(event.getSource().equals(rdbtnBareBones)){
				Wagon.setRation("Bare Bones");
			}
			else if(event.getSource().equals(rdbtnSteady)){
				Wagon.setPace(Pace.Steady);
			}
			else if(event.getSource().equals(rdbtnStrenuous)){
				Wagon.setPace(Pace.Strenuous);
			}
			else if(event.getSource().equals(rdbtnGrueling)){
				Wagon.setPace(Pace.Grueling);
			}
		}
	}
}